package com.fone.player.util;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.view.animation.Animation.AnimationListener;

public class deleteHistoryAnimationUtil {
	/**
	 * 防止动画执行过程中背景空白，屏幕跳；边执行，边控制view高度
	 * 
	 * @param v
	 *            要执行动画的View
	 * @param al
	 *            动画监听器，可为空
	 * @param measureHeight
	 *            view的实际高度，可不传，但显示时需要保证此高度不为0
	 * @param show
	 *            是显示还是隐藏
	 * @param ainmTime
	 *            动画时间
	 */
	public static void animHideShowView(final View v, AnimationListener al,
			int measureHeight, final boolean show, int ainmTime) {

		if (measureHeight == 0) {
			measureHeight = v.getMeasuredHeight();
		}
		final int heightMeasure = measureHeight;
		Animation anim = new Animation() {

			@Override
			protected void applyTransformation(float interpolatedTime,
					Transformation t) {

				if (interpolatedTime == 1) {

					v.setVisibility(show ? View.VISIBLE : View.GONE);
				} else {
					int height;
					if (show) {
						height = (int) (heightMeasure * interpolatedTime);
					} else {
						height = heightMeasure
								- (int) (heightMeasure * interpolatedTime);
					}
					v.getLayoutParams().height = height;
					v.requestLayout();
				}
			}

			@Override
			public boolean willChangeBounds() {
				return true;
			}
		};

		if (al != null) {
			anim.setAnimationListener(al);
		}
		anim.setDuration(ainmTime);
		v.startAnimation(anim);
	}
}
